﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true"
    CodeBehind="RegisterOld.aspx.cs" Inherits="Ashlen.Portal.Web.Views.Account.Register" %>

<asp:Content ID="registerContent" ContentPlaceHolderID="MainContent" runat="server">


    <script src="../../Content/MicrosoftAjax.debug.js" type="text/javascript"></script>
    <script src="../../Content/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<%--    <script src="../../Content/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Content/MicrosoftMvcAjax.js" type="text/javascript"></script>
--%>    
    <script src="../../Content/Account.js" type="text/javascript"></script>
    <script src="../../Content/UI/ui/ui.datepicker.js" type="text/javascript"></script>
    <link href="../../Content/UI/themes/default/ui.datepicker.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        $(document).ready(function() {

        $("#dateOfBirth").datepicker({ onSelect: function(date)
        {}, showOn: "both", yearRange: '1945:2008', dateFormat: 'dd-MM-yy'
        });
            $("#dateOfBirth").attr('readonly', true);
        });
        function setDateFromDialog(date) { $("#dialog").val(date); }

        var ddlCountries;
        var ddlStates;

        function pageLoad() {
            ddlCountries = $get("country");
            ddlStates = $get("state");
            myForm = $get("registerForm");
            $addHandler(ddlCountries, "change", bindOptions);
            // $addHandler(myForm, "submit", bindForm);
            bindOptions();
        }

        function bindOptions() {
            ddlStates.options.length = 0;
            var countryId = ddlCountries.value;

            if (countryId) {
                var url = "../Account/GetStatesForCountry/" + countryId;
                getContent(url, bindOptionResults);
            }
        }

        function bindOptionResults(data) {
            var newOption;
            var found;
            found = false;
            for (var k = 0; k < data.length; k++) {
                newOption = new Option(data[k].Name, data[k].ID);
                if ($get("selectedState") != null) {
                    if (data[k].ID == $get("selectedState").value) {
                        newOption.selected = true;
                        found = true;
                    }
                }
                ddlStates.options.add(newOption);
            }
            if (found == false) {
                ddlStates.value = data[0].ID;
            }
        }

        /**** should be in library ***/
        function getContent(url, callback) {
            var request = new Sys.Net.WebRequest();
            request.set_url(url);
            request.set_httpVerb("GET");
            var del = Function.createCallback(getContentResults, callback);
            request.add_completed(del);
            request.invoke();
        }

        function getContentResults(executor, eventArgs, callback) {
            if (executor.get_responseAvailable()) {
                callback(eval("(" + executor.get_responseData() + ")"));
            }
            else {
                if (executor.get_timedOut())
                    alert("Timed Out");
                else if (executor.get_aborted())
                    alert("Aborted");
            }
        }
       
    </script>

    <h2>
        Account Creation</h2>
    <p>
        Use the form below to create a new account.
    </p>
    <p>
        Passwords are required to be a minimum of
        <%=Html.Encode(ViewData["PasswordLength"])%>
        characters in length.<br />
        Items marked with an asterisk (*) are mandatory.
    </p>
    <p>
        <span style="color: Green"><strong>Please enter a valid email.
            <br />
            You will be sent a confirmation link via email which you will need to click before
            you can log in.</strong></span>
    </p>
    <div>
        <%
            var errors = ViewData["errors"] as IList<string>;
            if (errors != null) {
        %>
        <ul class="error" id="errors">
            <% foreach (string error in errors) { %>
            <li>
                <%= Html.Encode(error) %></li>
            <% } %>
        </ul>
        <%
            }
        %>
    </div>
    <%= Html.Hidden("selectedState")%>
    <div id="welcomeUserDiv"></div>
    <%using (Ajax.Form("Register", new AjaxOptions { OnSuccess = "showErrors", LoadingElementId = "myAnimatedGif" })) { %>
    <div>
        <table>
            <tr>
                <td>
                    <img src="../../Images/MessageSuccess.gif" alt="Success" visible="false" id="SuccessImage"
                        style="display: none" />
                </td>
                <td>
                    <div id="successDiv" style="color: Green">
                    </div>
                    <img id="myAnimatedGif" src="../../Images/loading_animated.gif" alt="Progress" visible="false"
                        style="display: none" />
                </td>
            </tr>
            <tr>
                <td>
                    Username:
                </td>
                <td>
                    <%= Html.TextBox("username")%>*
                </td>
            </tr>
            <tr>
                <td>
                    Email:
                </td>
                <td>
                    <%= Html.TextBox("email")%>*
                </td>
            </tr>
            <tr>
                <td>
                    Password:
                </td>
                <td>
                    <%= Html.Password("password")%>*
                </td>
            </tr>
            <tr>
                <td>
                    Confirm password:
                </td>
                <td>
                    <%= Html.Password("confirmPassword")%>*
                </td>
            </tr>
            <tr>
                <td>
                    Firstname:
                </td>
                <td>
                    <%= Html.TextBox("firstName")%>*
                </td>
            </tr>
            <tr>
                <td>
                    Lastname:
                </td>
                <td>
                    <%= Html.TextBox("lastName")%>*
                </td>
            </tr>
            <tr>
                <td>
                    Nickname:
                </td>
                <td>
                    <%= Html.TextBox("nickName")%>
                </td>
            </tr>
            <tr>
                <td>
                    Date of Birth:
                </td>
                <td>
                    <%= Html.TextBox("dateOfBirth")%>
                </td>
            </tr>
            <tr>
                <td>
                    Sex:
                </td>
                <td>
                    <%= Html.DropDownList("", "sex")%>*
                </td>
            </tr>
            <tr>
                <td>
                    Mobile:
                </td>
                <td>
                    <%= Html.TextBox("mobile")%>
                </td>
            </tr>
            <tr>
                <td>
                    Phone:
                </td>
                <td>
                    <%= Html.TextBox("phone")%>
                </td>
            </tr>
            <tr>
                <td>
                    Country:
                </td>
                <td>
                    <%= Html.DropDownList("", "country")%>*
                </td>
            </tr>
            <tr>
                <td>
                    State:
                </td>
                <td>
                    <select id="state" name="state">
                    </select>*
                </td>
            </tr>
            <tr>
                <td>
                    Postcode:
                </td>
                <td>
                    <%= Html.TextBox("postcode")%>
                </td>
            </tr>
            <tr>
                <td>
                    Send Me Community Alerts:
                </td>
                <td>
                    <%= Html.CheckBox("acceptCommunityEmail", ViewState["acceptCommunityEmail"])%>
                </td>
            </tr>
            <tr>
                <td>
                    Send Me Promotions:
                </td>
                <td>
                    <%= Html.CheckBox("acceptAdvertisingEmail", ViewState["acceptAdvertisingEmail"])%>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <!--Register-->
                <td>
                    <input type="submit" value="Register" />
                </td>
            </tr>
        </table>
    </div>
    <%} %>
</asp:Content>
